#!/bin/bash

set -e

UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")

if [ "$LOCAL" = "$REMOTE" ]; then
    #echo "Up-to-date"
    exit 1
elif [ "$LOCAL" = "$BASE" ]; then
    echo "Need to pull"
    exit 0
elif [ "$REMOTE" = "$BASE" ]; then
    echo "Need to push"
    exit 2
else
    echo "Diverged"
    exit 3
fi
